package com.test.demo.algorithm.simple;

import java.util.ArrayList;
import java.util.List;

public class Simple {

    public static void main(String[] args) {
        System.out.println( prime(10));
    }

    /**
     * @param n: an integer
     * @return: return all prime numbers within n.
     */
    public static List<Integer> prime(int n) {
        List<Integer> list = new ArrayList<>();
        // write your code here
        for (int i = 2; i <= n; i++) {
            boolean flag = true;
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    flag = false;
                }
            }
            if (flag){
                list.add(i);
            }
        }
        return list;
    }
}
